home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Libris Britannia 4
/
science library(b).zip
/
science library(b)
/
CUGUK
/
UTIL_SRC
/
C016.ZIP
/
CALC
/
SYMBOL.C
< prev
next >
Wrap
Text File
|
1990-01-19
|
1KB
|
59 lines
/* $Author: jkcohen $
* $Source: /mnt1/h/jkcohen/Source/C/Hoc/RCS/symbol.c,v $
* $Revision: 1.1 $ ; $Date: 87/03/16 21:18:21 $
* $State: Stab $
*/
#include "su.h"
#include "jc.h"
#include "hoc.h"
#include "ytab.h"
static Symbol *symlist = 0; /* symbol table: linked list */
Symbol *lookup(s) /* find s in symbol table */
register char *s;
Begin
register Symbol *sp;
For sp = symlist; sp != (Symbol *) 0; sp = sp->next Do
If strcmp(sp->name, s) == 0 Do
Return sp;
Endif
Endfor
Return 0; /* 0 ==> not found */
End
Symbol *install(s, t, d) /* install s in symbol table */
register char *s;
register int t;
double d;
Begin
register Symbol *sp;
char *emalloc();
sp = (Symbol *) emalloc(sizeof(Symbol));
sp->name = emalloc(strlen(s) + 1); /* +1 for '\0' */
strcpy(sp->name, s);
sp->type = t;
sp->u.val = d;
sp->next = symlist; /* put at front of list */
symlist = sp;
Return sp;
End
char *emalloc(n) /* check return from malloc */
register unsigned n;
Begin
register char *p;
char *malloc();
p = malloc(n);
If p == 0 Do
execerror("out of memory", (char *) 0);
Endif
Return p;
End